#region Using directives

using System;
using System.Text ;
using System.Data ;
using System.Collections ;

using WP.MF.DataEntity; 
using WP.MF.DataAccess; 
using WP.MF.BusinessRule; 
using WP.DB;
using WP.Commons;

#endregion
namespace WP.MF.BusinessLogical
{

	/*
	 * Created by SmartCreateCode Tool
	 */

    public class MSalesTaxBLL : IBusinessLogical
	{
		ArrayList multiList=new ArrayList ();
		MSalesTaxDAL mSalesTaxDAL =new MSalesTaxDAL();
        private DBAccess m_dBAccess = null;
        public DBAccess DBCon
        {
            get
            {
                return m_dBAccess;
            }
            set
            {
                m_dBAccess = value;
            }
        }

		public MSalesTaxBLL()
		{
		}

		#region Select MSalesTax
        public IDataEntity SelectDataByRecID(string strRecId)
        {
            DBAccess dBAccess = new DBAccess(false, false);
            MSalesTaxDEL mSalesTaxDEL = null;

            try
            {
                mSalesTaxDEL = mSalesTaxDAL.SelectDataByRecID(dBAccess, strRecId);
                return mSalesTaxDEL as IDataEntity;
            }
            catch (Exception e)
            {
                ExceptionManager.ProcessException(e);
                return null;
            }
            finally
            {
                dBAccess.CloseCon();
            }
        }
		#endregion

		#region Insert MSalesTax
        public bool Insert(IDataEntity iMSalesTaxDEL)
        {
            bool bReturn = true;
            MSalesTaxDEL mSalesTaxDEL = iMSalesTaxDEL as MSalesTaxDEL;
            //DBAccess dBAccess = null;
            //dBAccess = new DBAccess(false, true);
            m_dBAccess.BeginTran();

            try
            {
                bReturn = Insert(m_dBAccess, mSalesTaxDEL);
                if (bReturn)
                {
                    m_dBAccess.CommitTran();
                }
                else
                {
                    m_dBAccess.RollbackTran();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                m_dBAccess.RollbackTran();
                ExceptionManager.ProcessException(e);
                bReturn = false;
            }
            return bReturn;
        }
        public bool Insert(DBAccess dBAccess, MSalesTaxDEL mSalesTaxDEL)
        {
            bool bFlag = true;
            MSalesTaxBRL mSalesTaxBRL = new MSalesTaxBRL();

            if (mSalesTaxBRL.InsertValid(dBAccess, mSalesTaxDEL))
            {
                mSalesTaxDAL.InsertMSalesTax(dBAccess, mSalesTaxDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
		#endregion

		#region Update MSalesTax
        public bool Update(IDataEntity iMSalesTaxDEL)
        {
            bool bReturn = true;
            MSalesTaxDEL mSalesTaxDEL = iMSalesTaxDEL as MSalesTaxDEL;
            //DBAccess dBAccess = new DBAccess(false, true);
            m_dBAccess.BeginTran();

            try
            {
                bReturn = Update(m_dBAccess, mSalesTaxDEL);
                if (bReturn)
                {
                    m_dBAccess.CommitTran();
                }
                else
                {
                    m_dBAccess.RollbackTran();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                m_dBAccess.RollbackTran();
                ExceptionManager.ProcessException(e);
                return false;
            }

            return bReturn;
        }
        public bool Update(DBAccess dBAccess, MSalesTaxDEL mSalesTaxDEL)
        {
            bool bFlag = true;
            MSalesTaxBRL mSalesTaxBRL = new MSalesTaxBRL();

            if (mSalesTaxBRL.UpdateValid(dBAccess, mSalesTaxDEL))
            {
                mSalesTaxDAL.UpdateMSalesTax(dBAccess, mSalesTaxDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
		#endregion

        #region public bool Delete()
        public bool Delete(string strRecId, byte[] btOldRecStamp)
        {
            DBAccess dBAccess = new DBAccess(false, true);
            bool bFlag = false;

            try
            {
                if (new MSalesTaxBRL().DeleteValid(dBAccess, strRecId, btOldRecStamp))
                {
                    DataFunctions.DeleteByRecID(dBAccess, "mSalesTax", strRecId);

                    dBAccess.CommitTranAndCloseCon();

                    bFlag = true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
            }

            return bFlag;
        }

        #endregion
	}
}